package com.jmars.TS.service.impl;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.jmars.TS.common.JiumiConfig;
import com.jmars.TS.entity.*;
import com.jmars.TS.mapper.db1.SysJobLogMapper;
import com.jmars.TS.mapper.db1.WMSInOutMapper;
import com.jmars.TS.service.BatchService;
import com.jmars.TS.service.NRIBService;
import com.jmars.TS.service.SysJobLogService;
import com.jmars.TS.util.DateUtils;
import com.jmars.TS.util.OkHttpUtil;
import lombok.var;
import org.apache.commons.codec.digest.DigestUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.transaction.interceptor.TransactionAspectSupport;

import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;


/**
 * @Author: whd
 * @DateTime: 2024/09/12 13:41
 * @msg:
 */
@Service
public class NRIBServiceImpl implements NRIBService {
    private static final Logger logger = LoggerFactory.getLogger(NRIBServiceImpl.class);
//
    /** 系统基础配置 */
    @Autowired
    private JiumiConfig jiumiConfig;

    @Autowired
    WMSInOutMapper wmsInOutMapper;

    @Autowired
    SysJobLogMapper sysJobLogMapper;

    @Autowired
    BatchService batchService;


    @Override
    @Transactional
    public boolean inSkuTask() {

        boolean isSuccess = false;
        String jobName ="同步商品档案";
        String jobTag ="inSkuTask";
        String jobMsg ="";
        String exceptionInfo ="";

        long startTime = System.currentTimeMillis();

        try {
            // 调用接口获取数据
            logger.info("[{0}][{1}] ------>> 同步数据开始", jobTag, jobName);


            String strRet = httpPost_getArticleList();
            NribResult result = JSON.parseObject(strRet, NribResult.class);
            logger.info(result.toString());

            // 返回成功
            if (result != null && result.code.equals("200")) {

                List<InSku> inSkuList = JSON.parseArray(result.body, InSku.class);

                // 先情况表再插入数据
                wmsInOutMapper.deleteInSku();
                wmsInOutMapper.deleteInSkuBarcode();
                wmsInOutMapper.deleteInSkuPosition();

                for (InSku item : inSkuList) {
                    //插入商品档案
                    wmsInOutMapper.insertInSku(item);

                    //插入条码列表
                    List<InSkuBarcode> barcodeList = item.barCodeList;
                    if (barcodeList != null) {
                        for (InSkuBarcode barcode : barcodeList) {
                            wmsInOutMapper.insertInSkuBarcode(barcode);
                        }
                    }

                    //插入货物列表
                    List<InSkuPositon> positonList = item.goodsPositionList;
                    if (positonList != null) {
                        for (InSkuPositon positon : positonList) {
                            wmsInOutMapper.insertInSkuPosition(positon);
                        }
                    }
                }

                // 执行存储过程
                HashMap<String, Object> params = new HashMap<>();
                wmsInOutMapper.callSpSqlInSku(params);
                String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
                logger.info("[callSpSqlInSku] 返回消息 sp_out = {}", spOut);
                isSuccess = true;

                if (inSkuList.size() > 0) {
                    logger.info("[inSkuTask][商品档案] ------>> 数量：" + inSkuList.size());
                }
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
            exceptionInfo = e.getMessage();
        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg = "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{0}][{1}] ------>> 同步数据完成",jobTag,jobName);
        return isSuccess;
    }

    @Override
    @Transactional
    public boolean inLocationTask() {

        boolean isSuccess = false;
        String jobName ="店铺档案";
        String jobTag ="inLocationTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {


            // 调用接口获取数据

            String strRet = httpPost_getStoreList();
            NribResult result = JSON.parseObject(strRet, NribResult.class);
            logger.info(result.toString());

            // 返回成功
            if (result != null && result.code.equals("200")) {

                List<InLocation> inLocationList = JSON.parseArray(result.body, InLocation.class);

                // 先情况表再插入数据
                wmsInOutMapper.deleteInLocation();
                for (InLocation item : inLocationList) {
                    wmsInOutMapper.insertInLocation(item);
                }

                // 执行存储过程
                if (inLocationList.size() > 0) {
                    HashMap<String, Object> params = new HashMap<>();
                    wmsInOutMapper.callSpSqlInLocation(params);
                    String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
                    logger.info("[callSpSqlInLocation] 返回消息 sp_out = {}", spOut);

                    isSuccess = true;
                    logger.info("[inLocationTask][店铺档案]------>>数量：" + inLocationList.size());

                }
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
            exceptionInfo =  e.getMessage();
        }
        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return isSuccess;
    }

    @Override
    @Transactional
    public boolean inSupplyTask() {

        boolean isSuccess = false;
        String jobName ="同步供应商档案";
        String jobTag ="inSupplyTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 调用接口获取数据

            String strRet = httpPost_getVendorList();
            NribResult result = JSON.parseObject(strRet, NribResult.class);
            logger.info(result.toString());

            // 返回成功
            if (result != null && result.code.equals("200")) {

                List<InSupply> inSupplyList = JSON.parseArray(result.body, InSupply.class);

                // 先情况表再插入数据
                wmsInOutMapper.deleteInSupply();
                for (InSupply item : inSupplyList) {
                    wmsInOutMapper.insertInSupply(item);
                }

                // 执行存储过程
                HashMap<String, Object> params = new HashMap<>();
                wmsInOutMapper.callSpSqlInSupply(params);
                String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
                logger.info("[callSpSqlInSupply] 返回消息 sp_out = {}", spOut);
                jobMsg += " spOut：" + spOut + "毫秒";

                isSuccess = true;

                if (inSupplyList.size() > 0) {
                    logger.info("[inSupplyTask][供应商档案]------>>数量：" + inSupplyList.size());
                }
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
            exceptionInfo =  e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return isSuccess;
    }

    @Override
    @Transactional
    public boolean inLineTask() {

        boolean isSuccess = false;
        String jobName ="路线档案";
        String jobTag ="inLineTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {

            // 调用接口获取数据
            String strRet = httpPost_getRouteList();
            NribResult result = JSON.parseObject(strRet, NribResult.class);
            logger.info(result.toString());

            // 返回成功
            if (result != null && result.code.equals("200")) {

                List<InLine> inLineList = JSON.parseArray(result.body, InLine.class);

                // 先情况表再插入数据
                wmsInOutMapper.deleteInLine();
                for (InLine item : inLineList) {
                    wmsInOutMapper.insertInLine(item);
                }

                isSuccess = true;

                // 执行存储过程
                HashMap<String, Object> params = new HashMap<>();
                wmsInOutMapper.callSpSqlInLine(params);
                String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
                logger.info("[callSpSqlInLine] 返回消息 sp_out = {}", spOut);

                if (inLineList.size() > 0) {
                    logger.info("[inLineTask][路线档案]------>>数量：" + inLineList.size());
                }
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }

    @Override
    @Transactional
    public boolean inWmsStockTask() {

        boolean isSuccess = false;
        String jobName ="获取商品库存";
        String jobTag ="inWmsStockTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 调用接口获取数据

            String strRet = httpPost_getWmsStock();
            NribResult result = JSON.parseObject(strRet, NribResult.class);
            logger.info(result.toString());

            // 返回成功
            if (result != null && result.code.equals("200")) {

                List<InWmsStock> inWmsStockList = JSON.parseArray(result.body, InWmsStock.class);

                // 先情况表再插入数据
                wmsInOutMapper.deleteInWmsStock();
                for (InWmsStock item : inWmsStockList) {
                    int cnt = wmsInOutMapper.insertInWmsStock(item);
                }


                isSuccess = true;

                // 执行存储过程
                HashMap<String, Object> params = new HashMap<>();
                wmsInOutMapper.callSpSqlInWmsStock(params);
                String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
                logger.info("[callSpSqlInWmsStock] 返回消息 sp_out = {}", spOut);
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return isSuccess;
    }

    @Override
    @Transactional
    public boolean inInfGoodsMoreTask() {

        boolean isSuccess = false;
        String jobName ="自动同步wms获取商品附加属性";
        String jobTag ="inInfGoodsMore";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 调用接口获取数据
            String strRet = httpPost_getInfGoodsMore();
            NribResult result = JSON.parseObject(strRet, NribResult.class);
            logger.info(result.toString());

            // 返回成功
            if (result != null && result.code.equals("200")) {

                List<InInfGoodsMore> inInfGoodsMoreList = JSON.parseArray(result.body, InInfGoodsMore.class);

                // 先情况表再插入数据
                wmsInOutMapper.deleteInInfGoodsMore();
                for (InInfGoodsMore item : inInfGoodsMoreList) {
                    int cnt = wmsInOutMapper.insertInInfGoodsMore(item);
                }

                // 执行存储过程
                HashMap<String, Object> params = new HashMap<>();
                wmsInOutMapper.call_SP_SQL_IN_INF_GOODS_MORE(params);
                String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
                logger.info("[call_SP_SQL_IN_INF_GOODS_MORE] 返回消息 sp_out = {}", spOut);

                isSuccess = true;

                if (inInfGoodsMoreList.size() > 0) {

                }
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return isSuccess;
    }

    @Override
    @Transactional
    public boolean inInfStockPositionTask() {

        boolean isSuccess = false;
        String jobName ="自动同步货位信息";
        String jobTag ="inInfStockPositionTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 调用接口获取数据
            String strRet = httpPost_getInfStockPosition();
            NribResult result = JSON.parseObject(strRet, NribResult.class);
            logger.info(result.toString());

            // 返回成功
            if (result != null && result.code.equals("200")) {

                List<InInfStockPosition> inInfStockPositionList = JSON.parseArray(result.body, InInfStockPosition.class);

                // 先情况表再插入数据
                wmsInOutMapper.deleteInInfStockPosition();
                for (InInfStockPosition item : inInfStockPositionList) {
                    int cnt = wmsInOutMapper.insertInInfStockPosition(item);
                }

                // 执行存储过程
                if (inInfStockPositionList.size() > 0) {
                    HashMap<String, Object> params = new HashMap<>();
                    wmsInOutMapper.call_SP_SQL_IN_INF_STOCK_POSITION(params);
                    String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
                    logger.info("[call_SP_SQL_IN_INF_STOCK_POSITION] 返回消息 sp_out = {}", spOut);

                    isSuccess = true;

                }
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return isSuccess;
    }

    @Override
    @Transactional
    public boolean in_getWmsStockByPosition() {

        boolean isSuccess = false;
        String jobName ="自动同步WMS查询库存货位";
        String jobTag ="in_getWmsStockByPosition";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 调用接口获取数据
            String strRet = httpPost_getWmsStockByPosition();
            NribResult result = JSON.parseObject(strRet, NribResult.class);
            logger.info(result.toString());

            // 返回成功
            if (result != null && result.code.equals("200")) {

                List<InGetWmsStockByPosition> inGetWmsStockByPositionList = JSON.parseArray(result.body, InGetWmsStockByPosition.class);

                // 先情况表再插入数据
                wmsInOutMapper.deleteInGetWmsStockByPositionList();
                for (InGetWmsStockByPosition item : inGetWmsStockByPositionList) {
                    int cnt = wmsInOutMapper.insertInGetWmsStockByPosition(item);
                }
                isSuccess = true;

                // 执行存储过程
                if (inGetWmsStockByPositionList.size() > 0) {
                    HashMap<String, Object> params = new HashMap<>();
                    wmsInOutMapper.call_SP_SQL_IN_GetWmsStockByPosition(params);
                    String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
                    logger.info("[call_SP_SQL_IN_GetWmsStockByPosition] 返回消息 sp_out = {}", spOut);
                }
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return isSuccess;
    }

    @Override
    @Transactional
    public boolean inDCCostTask() {

        boolean isSuccess = false;
        String jobName ="获取大库成本";
        String jobTag ="inDCCostTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {

            // 调用接口获取数据
            String strRet = httpPost_getDCCost();
            NribResult result = JSON.parseObject(strRet, NribResult.class);
            logger.info(result.toString());

            // 返回成功
            if (result != null && result.code.equals("200")) {

                List<InDCCost> inDCCostList = JSON.parseArray(result.body, InDCCost.class);

                // 先情况表再插入数据
                wmsInOutMapper.deleteInDCCost();
                for (InDCCost item : inDCCostList) {
                    int cnt = wmsInOutMapper.insertInDCCost(item);
                }
                isSuccess = true;

            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return isSuccess;
    }

    @Override
    @Transactional
    public boolean inMasterVendorTask() {

        boolean isSuccess = false;
        String jobName ="获取供应商商品关系";
        String jobTag ="inMasterVendorTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {

            // 调用接口获取数据
            String strRet = httpPost_getMasterVendor();
            NribResult result = JSON.parseObject(strRet, NribResult.class);
            logger.info(result.toString());

            // 返回成功
            if (result != null && result.code.equals("200")) {

                List<InSkuSupply> inSkuSupplyList = JSON.parseArray(result.body, InSkuSupply.class);

                // 先情况表再插入数据
                wmsInOutMapper.deleteInSkuSupply();
                for (InSkuSupply item : inSkuSupplyList) {
                    int cnt = wmsInOutMapper.insertInSkuSupply(item);
                }
                isSuccess = true;

            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return isSuccess;
    }

    @Override
    @Transactional
    public boolean in_getStoreToDcApply(String startDate,String endDate) {

        boolean isSuccess = false;
        String jobName ="自动同步门店退仓库退货数据";
        String jobTag ="in_getStoreToDcApply";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 调用接口获取数据
            String strRet = httpPost_getStoreToDcApply(startDate, endDate);
            NribResult result = JSON.parseObject(strRet, NribResult.class);
            logger.info(result.toString());

            // 返回成功
            if (result != null && result.code.equals("200")) {

                List<InGetStoreToDcApply> itemList = JSON.parseArray(result.body, InGetStoreToDcApply.class);

                // 先情况表再插入数据
//            wmsInOutMapper.deleteInGetStoreToDcApply();
//            for (InGetStoreToDcApply item:itemList ) {
//
//                int cnt = wmsInOutMapper.insertInGetStoreToDcApply(item);
//            }
                if (itemList != null) {
                    for (InGetStoreToDcApply item : itemList) {
                        // 先情况表再插入数据
                        if (wmsInOutMapper.existInGetStoreToDcApply(item) > 0) {
                            //wmsInOutMapper.updateInAsnHeader(item);
                        } else {
                            int cnt = wmsInOutMapper.insertInGetStoreToDcApply(item);
                        }
                    }

                }

                isSuccess = true;

                // 执行存储过程
                if (itemList.size() > 0) {
                    HashMap<String, Object> params = new HashMap<>();
                    wmsInOutMapper.callSpSqlInGetStoreToDcApply(params);
                    String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
                    logger.info("[callSpSqlInGetStoreToDcApply] 返回消息 sp_out = {}", spOut);

                    isSuccess = true;

                }
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return isSuccess;
    }

    @Override
    @Transactional
    public boolean in_getDcToSupplierApply(String startDate,String endDate) {

        boolean isSuccess = false;
        String jobName ="自动同步仓库退供应商退货数据";
        String jobTag ="in_getDcToSupplierApply";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 调用接口获取数据
            String strRet = httpPost_getDcToSupplierApply(startDate, endDate);
            NribResult result = JSON.parseObject(strRet, NribResult.class);
            logger.info(result.toString());

            // 返回成功
            if (result != null && result.code.equals("200")) {

                List<InGetDcToSupplierApply> itemList = JSON.parseArray(result.body, InGetDcToSupplierApply.class);
                //wmsInOutMapper.deleteInGetDcToSupplierApply();
                if (itemList != null) {
                    for (InGetDcToSupplierApply item : itemList) {
                        //int cnt = wmsInOutMapper.insertInGetDcToSupplierApply(item);

                        // 先情况表再插入数据
                        if (wmsInOutMapper.existInGetDcToSupplierApply(item) > 0) {
                            //wmsInOutMapper.updateInAsnHeader(item);
                        } else {
                            int cnt = wmsInOutMapper.insertInGetDcToSupplierApply(item);
                        }
                    }

                }
            }

            // 更新退货数量
            List<InGetDcToSupplierApply> supplyList = wmsInOutMapper.selectSupplyInDcToSupplierApplyList();
            if (supplyList != null && supplyList.size() > 0) {
                String str_supply = "";
                BigDecimal nowamount = null;
                List<GetStoreReturnListResponseBody> itemList = null;
                for (InGetDcToSupplierApply item : supplyList) {
                    // 判断
                    if (!str_supply.equals(item.getVendorId())) {
                        // 调用接口获取数据
                        str_supply = item.getVendorId();
                        String res_data_supply = httpPost_getStoreReturnList(str_supply);
                        NribResult result2 = JSON.parseObject(res_data_supply, NribResult.class);
                        //logger.info(result2.toString());

                        // 返回成功
                        if (result2 != null && result2.code.equals("200")) {
                            itemList = JSON.parseArray(result2.body, GetStoreReturnListResponseBody.class);
                        }

                    }


                    if (itemList != null && itemList.size() > 0) {
                        for (GetStoreReturnListResponseBody gdsItem : itemList) {
                            if (gdsItem.getGdsincode().equals(item.getSku())) {
                                nowamount = gdsItem.getNowamount();
                                item.setNowamount(nowamount);
                                break; // 找到匹配项后退出循环
                            }
                        }
                    }

                    // 把null更新成0
                    if (item.getNowamount() == null) {
                        item.setNowamount(new BigDecimal(0));
                    }

                    // 先情况表再插入数据
                    logger.info(item.toString());
                    wmsInOutMapper.updateNowamount(item);

                    // 数量为0的不调用存储过程
                    if (item.getNowamount() != new BigDecimal(0)) {

                        // 执行存储过程(已废弃不用了)
//                        HashMap<String, Object> params = new HashMap<>();
//                        params.put("sp_org", item.getInvOrg());
//                        params.put("sp_consignor", item.getConsignor());
//                        params.put("sp_sku", item.getSku());
//                        params.put("sp_qty", item.getNowamount().intValue());  // 转int
//                        wmsInOutMapper.callSpSqlInvReturnSku(params);
//                        String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
//                        logger.info("[callSpSqlInGetDcToSupplierApply] 返回消息 sp_out = {}", spOut);

                    }

                }
            }


            // 执行存储过程
            HashMap<String, Object> params = new HashMap<>();
            wmsInOutMapper.callSpSqlInGetDcToSupplierApply(params);
            String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
            logger.info("[callSpSqlInGetDcToSupplierApply] 返回消息 sp_out = {}", spOut);

            isSuccess = true;
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return isSuccess;
    }


    @Override
//    @Transactional
    public boolean inAsnTask(String asnType, String startDate, String endDate) {

        boolean isSuccess = false;
        String jobName ="自动同步收货数据";
        String jobTag ="inAsnTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {


            // 调用接口获取数据
            String strRet = httpPost_getTransInDtl(asnType, startDate, endDate);
            NribResult result = JSON.parseObject(strRet, NribResult.class);
            logger.info(result.toString());

            // 返回成功
            if (result != null && result.code.equals("200")) {

                List<InAsnHeader> inAsnHeaderList = JSON.parseArray(result.body, InAsnHeader.class);

                if (inAsnHeaderList != null) {
                    for (InAsnHeader item : inAsnHeaderList) {
                        batchService.batchInAsn(item);
//                    batchInAsn(item);
                    }

                    // 执行存储过程
                    HashMap<String, Object> params = new HashMap<>();
                    wmsInOutMapper.callSpSqlInAsn(params);
                    String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
                    logger.info("[callSpSqlInAsn] 返回消息 sp_out = {}", spOut);


                    if (inAsnHeaderList.size() > 0) {

                        logger.info("[inAsnTask][收货指令]------>>数量：" + inAsnHeaderList.size());

                    }
                }

                isSuccess = true;

            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            exceptionInfo = e.getMessage();

        }
        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return isSuccess;
    }

    public void batchInAsn(InAsnHeader item) {
        if(wmsInOutMapper.existInAsnHeader(item) > 0){
            wmsInOutMapper.updateInAsnHeader(item);
        }
        else{
            wmsInOutMapper.insertInAsnHeader(item);
            for (var detail:item.transInDtl ) {
                wmsInOutMapper.insertInAsnDetail(detail);
            }
        }

    }

    @Override
//    @Transactional
    public boolean inSoTask(String soType, String startDate, String endDate, String soNo) {

        boolean isSuccess = false;
        String jobName ="自动同步发货指令";
        String jobTag ="inSoTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {

            // 20250606 add 要货单数据同步方式切换
            // 01 要货单数据不再通过接口获取由野村直接插入中间表，直接调存储过程
            if(soType.equals("01"))
            {
                HashMap<String, Object> params = new HashMap<>();
                wmsInOutMapper.callSpSqlInSo(params);
                String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
                logger.info("[callSpSqlInSo] 返回消息 sp_out = {}", spOut);


                isSuccess = true;
                logger.info("[inSoTask][要货单数据 01]完成" );
            }

            // 02 门店差异数据
            if(soType.equals("02")) {


                // 调用接口获取数据
                String strRet = httpPost_getTransOutDtl(soType, startDate, endDate, soNo);
                NribResult result = JSON.parseObject(strRet, NribResult.class);
                logger.info(result.toString());


                // 返回成功
                if (result != null && result.code.equals("200")) {

                    List<InSoHeader> inSoHeaderList = JSON.parseArray(result.body, InSoHeader.class);

                    if (inSoHeaderList != null) {
                        for (InSoHeader item : inSoHeaderList) {
                            batchService.batchInSo(item);

//                    batchInSo(item); // 插入明细和表头
                        }

                        // 执行存储过程
                        if (inSoHeaderList.size() > 0) {
                            HashMap<String, Object> params = new HashMap<>();
                            wmsInOutMapper.callSpSqlInSo(params);
                            String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
                            logger.info("[callSpSqlInSo] 返回消息 sp_out = {}", spOut);


                            isSuccess = true;
                            logger.info("[inSoTask][发货指令 02]------>>数量：" + inSoHeaderList.size());

                        }
                    }

                }
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒;";
        jobMsg += "参数:soType="+soType+", startDate=" + startDate + ",endDate="+ endDate + ",soNo="+soNo;

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }



    @Override
//    @Transactional
    public boolean outAsnTask() {

        boolean isSuccess = false;
        String jobName ="收货单回传";
        String jobTag ="outAsnTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 执行存储过程
            HashMap<String, Object> params = new HashMap<>();
            wmsInOutMapper.callSpSqlOutAsn(params);
            String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
            logger.info("[callSpSqlOutAsn] 返回消息 sp_out = {}", spOut);


            // 查询数据
            List<OutAsn> outAsnList = wmsInOutMapper.selectOutAsnList();

            // 提交接口
            if (outAsnList != null && outAsnList.size() > 0) {

                String strRet = httpPost_saveReceiveDtl(outAsnList);
                NribResult result = JSON.parseObject(strRet, NribResult.class);
                logger.info("post responseData====> {}", strRet);
                logger.info(result.toString());

                // 返回成功
                if (result != null && result.code.equals("200")) {
                    logger.info("更新 trans_status = 1");
                    for (var os : outAsnList) {
                        os.setTrans_status("1");
                        wmsInOutMapper.updateOutAsn(os); // 成功 trans_status = 1
                    }
                } else {
//                    logger.info("更新 trans_status = 9");
//                    for (var os : outAsnList) {
//                        os.setTrans_status("9");
//                        wmsInOutMapper.updateOutAsn(os); // 失败 trans_status = 9
//                    }
                }

                isSuccess = true;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }

    @Override
//    @Transactional
    public boolean outSoTask() {

        boolean isSuccess = false;
        String jobName ="发货单回传";
        String jobTag ="outSoTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 执行存储过程
            HashMap<String, Object> params = new HashMap<>();
            wmsInOutMapper.callSpSqlOutSo(params);
            String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
            logger.info("[callSpSqlOutSo] 返回消息 sp_out = {}", spOut);


            // 查询数据
            List<OutSo> outSoList = wmsInOutMapper.selectOutSoList();

            // 提交接口
            if (outSoList != null && outSoList.size() > 0) {
                String strRet = httpPost_saveDeliveryDtl(outSoList);
                NribResult result = JSON.parseObject(strRet, NribResult.class);
                logger.info("post responseData====> {}", strRet);
                logger.info(result.toString());

                // 返回成功
                if (result != null && result.code.equals("200")) {
                    logger.info("更新 trans_status = 1");
                    for (var os : outSoList) {
                        os.setTrans_status("1");
                        wmsInOutMapper.updateOutSo(os); // 成功 trans_status = 1
                    }
                } else {
//                    logger.info("更新 trans_status = 9");
//                    for (var os : outSoList) {
//                        os.setTrans_status("9");
//                        wmsInOutMapper.updateOutSo(os); // 失败 trans_status = 9
//                    }
                }


                isSuccess = true;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }

    @Override
//    @Transactional
    public boolean outAsn2Task() {

        boolean isSuccess = false;
        String jobName ="门店退仓库实际退货回传";
        String jobTag ="outAsn2Task";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 执行存储过程
            HashMap<String, Object> params = new HashMap<>();
            wmsInOutMapper.callSpSqlOutAsn2(params);
            String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
            logger.info("[callSpSqlOutAsn2] 返回消息 sp_out = {}", spOut);


            // 查询数据
            List<OutAsn2> outAsn2List = wmsInOutMapper.selectOutAsn2List();

            // 提交接口
            if (outAsn2List != null && outAsn2List.size() > 0) {
                String strRet = httpPost_saveStoreToDcStock(outAsn2List);
                NribResult result = JSON.parseObject(strRet, NribResult.class);
                logger.info("post responseData====> {}", strRet);
                logger.info(result.toString());

                // 返回成功
                if (result != null && result.code.equals("200")) {
                    logger.info("更新 trans_status = 1");
                    for (var os : outAsn2List) {
                        os.setTrans_status("1");
                        wmsInOutMapper.updateOutAsn2(os); // 成功 trans_status = 1
                    }
                } else {
//                    logger.info("更新 trans_status = 9");
//                    for (var os : outAsn2List) {
//                        os.setTrans_status("9");
//                        wmsInOutMapper.updateOutAsn2(os); // 失败 trans_status = 9
//                    }
                }


                isSuccess = true;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }

    @Override
//    @Transactional
    public boolean outSo2Task() {

        boolean isSuccess = false;
        String jobName ="仓库退供应商退货数据回传";
        String jobTag ="outSo2Task";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 执行存储过程
            HashMap<String, Object> params = new HashMap<>();
            wmsInOutMapper.callSpSqlOutSo2(params);
            String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
            logger.info("[callSpSqlOutSo2] 返回消息 sp_out = {}", spOut);


            // 查询数据
            List<OutSo2> outSo2List = wmsInOutMapper.selectOutSo2List();

            // 提交接口
            if (outSo2List != null && outSo2List.size() > 0) {
                String strRet = httpPost_saveGoodsReturnSupplier(outSo2List);
                NribResult result = JSON.parseObject(strRet, NribResult.class);
                logger.info("post responseData====> {}", strRet);
                logger.info(result.toString());

                // 返回成功
                if (result != null && result.code.equals("200")) {
                    logger.info("更新 trans_status = 1");
                    for (var os : outSo2List) {
                        os.setTrans_status("1");
                        wmsInOutMapper.updateOutSo2(os); // 成功 trans_status = 1
                    }
                } else {
//                    logger.info("更新 trans_status = 9");
//                    for (var os : outSo2List) {
//                        os.setTrans_status("9");
//                        wmsInOutMapper.updateOutSo2(os); // 失败 trans_status = 9
//                    }
                }


                isSuccess = true;
                logger.info("[outSo2Task][退货单回传]------>>同步数据完成");
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }

    @Override
//    @Transactional
    public boolean outInvTask() {

        boolean isSuccess = false;
        String jobName ="每日库存回传";
        String jobTag ="outInvTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 执行存储过程
            HashMap<String, Object> params = new HashMap<>();
            String stringList = wmsInOutMapper.callSpSqlOutInv(params);
            String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
            logger.info("[callSpSqlOutInv] 返回消息 sp_out = {}", spOut);

            if(!"success".equals(spOut)){
                exceptionInfo += "存储过程报错：" + spOut;
            }

            // 查询数据
            List<OutInv> outInvList = wmsInOutMapper.selectOutInvList();

            // 提交接口
            if (outInvList != null && outInvList.size() > 0) {
                String strRet = httpPost_saveInventoryDaily(outInvList);

                isSuccess = true;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }

    @Override
//    @Transactional
    public boolean outInv2Task() {

        boolean isSuccess = false;
        String jobName ="库存异动回传";
        String jobTag ="outInv2Task";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 执行存储过程
            HashMap<String, Object> params = new HashMap<>();
            String stringList = wmsInOutMapper.callSpSqlOutInv2(params);
            String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
            logger.info("[callSpSqlOutInv2] 返回消息 sp_out = {}", spOut);

            if(!"success".equals(spOut)){
                exceptionInfo += "存储过程报错：" + spOut;
            }

            // jobType 异动类型, 大写字母 I 加库存, O 减库存, 这个表数量都写正数吧

            // 查询数据
            List<OutInv2> outInv2List = wmsInOutMapper.selectOutInv2List();

            // 提交接口
            if (outInv2List != null && outInv2List.size() > 0) {
                String strRet = httpPost_saveInventoryMovement(outInv2List);
                NribResult result = JSON.parseObject(strRet, NribResult.class);
                logger.info(result.toString());

                // 返回成功
                if (result != null && result.code.equals("200")) {
                    logger.info("更新 trans_status = 1");
                    for (var os : outInv2List) {
                        os.setTrans_status("1");
                        wmsInOutMapper.updateOutInv2(os); // 成功 trans_status = 1
                    }
                } else {
//                    logger.info("更新 trans_status = 9");
//                    for (var os : outInv2List) {
//                        os.setTrans_status("9");
//                        wmsInOutMapper.updateOutInv2(os); // 失败 trans_status = 9
//                    }
                }

                isSuccess = true;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }

    @Override
    public boolean outInv2BSTask() {

        boolean isSuccess = false;
        String jobName ="报损调整回传";
        String jobTag ="outInv2BSTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 执行存储过程
            HashMap<String, Object> params = new HashMap<>();
            String stringList = wmsInOutMapper.callSpSqlOutInv2BS(params);
            String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
            logger.info("[callSpSqlOutInv2BS] 返回消息 sp_out = {}", spOut);

            if(!"success".equals(spOut)){
                exceptionInfo += "存储过程报错：" + spOut;
            }

            // jobType 异动类型, 大写字母 I 加库存, O 减库存, 这个表数量都写正数吧

            // 查询数据
            List<OutInv2BS> outInv2BSList = wmsInOutMapper.selectOutInv2BSList();

            // 提交接口
            if (outInv2BSList != null && outInv2BSList.size() > 0) {
                String strRet = httpPost_saveWriteOffRecord(outInv2BSList);
                NribResult result = JSON.parseObject(strRet, NribResult.class);
                logger.info(result.toString());

                // 返回成功
                if (result != null && result.code.equals("200")) {
                    logger.info("更新 trans_status = 1");
                    for (var os : outInv2BSList) {
                        os.setTrans_status("1");
                        wmsInOutMapper.updateOutInv2BS(os); // 成功 trans_status = 1
                    }
                } else {
//                    logger.info("更新 trans_status = 9");
//                    for (var os : outInv2List) {
//                        os.setTrans_status("9");
//                        wmsInOutMapper.updateOutInv2(os); // 失败 trans_status = 9
//                    }
                }

                isSuccess = true;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }

    @Override
//    @Transactional
    public boolean outPickerRecordTask() {

        boolean isSuccess = false;
        String jobName ="拣货人记录回传";
        String jobTag ="outPickerRecordTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 执行存储过程
            HashMap<String, Object> params = new HashMap<>();
            wmsInOutMapper.callSpSqlOutPickerRecord(params);
            String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
            logger.info("[outPickerRecordTask] 返回消息 sp_out = {}", spOut);


            // 查询数据
            List<OutPickerRecord> outPickerRecordList = wmsInOutMapper.selectOutPickerRecordList();

            // 提交接口
            List<OutPickerRecord> newOutPickerRecordList = new ArrayList<>();
            if (outPickerRecordList != null && outPickerRecordList.size() > 0) {

                // 按pickbillno分组
                Map<String, List<OutPickerRecord>> groupedByPickbillno = outPickerRecordList.stream()
                        .collect(Collectors.groupingBy(
                                OutPickerRecord::getPickbillno   // 按单号分组
                        ));

                /// 遍历分组后的记录
                for (Map.Entry<String, List<OutPickerRecord>> entry : groupedByPickbillno.entrySet()) {
                    String pickbillno = entry.getKey();
                    List<OutPickerRecord> recordsForPickbillno = entry.getValue();

                    // 将当前pickbillno的记录添加到newOutPickerRecordList
                    newOutPickerRecordList.addAll(recordsForPickbillno);

                    // 检查newOutPickerRecordList的大小，如果大于500，则提交所有记录 (接口最大支持800条)
                    while (newOutPickerRecordList.size() >= 500) {
                        // 提交所有当前批次的记录
                        submitOutPickerRecordList(new ArrayList<>(newOutPickerRecordList));
                        // 清空newOutPickerRecordList以准备下一次添加
                        newOutPickerRecordList.clear();
                    }
                }

                // 提交剩余的记录，如果有的话
                if (!newOutPickerRecordList.isEmpty()) {
                    submitOutPickerRecordList(newOutPickerRecordList);
                    newOutPickerRecordList.clear();
                }

                // 清空分组Map以准备下一次操作
                groupedByPickbillno.clear();


                isSuccess = true;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            exceptionInfo = e.getMessage();
        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }

    // 提交订单拣选列表的方法
    private void submitOutPickerRecordList(List<OutPickerRecord> outPickerRecordList ) {

        String strRet = httpPost_savePickerRecord(outPickerRecordList);
        NribResult result = JSON.parseObject(strRet,NribResult.class);
        logger.info("post responseData====> {}", strRet); // log返回值

        // 返回成功
        if(result!= null && result.code.equals("200")){
            for (var os : outPickerRecordList) {
                os.setTrans_status("1");
                wmsInOutMapper.updateOutPickerRecord(os); // 成功 trans_status = 1
            }
        }
    }


    @Override
    public boolean outWmsGoodsTask() {

        boolean isSuccess = false;
        String jobName ="保存拣货数量回传";
        String jobTag ="outWmsGoodsTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 执行存储过程
            HashMap<String, Object> params = new HashMap<>();
            wmsInOutMapper.call_SP_SQL_IN_ORDER_PCIK_STS_wms(params);
            String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
            logger.info("[call_SP_SQL_IN_ORDER_PCIK_STS_wms] 返回消息 sp_out = {}", spOut);

            if(!"success".equals(spOut)){
                exceptionInfo += "存储过程报错：" + spOut;
            }

            // 查询数据
            List<OutWmsGoods> outWmsGoodsList = wmsInOutMapper.selectOutWmsGoodsList();

            // 提交接口
            List<OutWmsGoods> newOutWmsGoodsList = new ArrayList<>();
            if (outWmsGoodsList != null && outWmsGoodsList.size() > 0) {


                int count = 0; // 用于跟踪已处理的记录数
                String str_invOrg = "";
                String str_consignor = "";

                for (var outWmsGoods : outWmsGoodsList) {
                    // 添加当前记录到临时列表
                    newOutWmsGoodsList.add(outWmsGoods);
                    count++;

                    // 检查是否达到100条记录，如果是，则提交并清空列表
                    if (count % 200 == 0) {

                        submitOutWmsGoodsList(newOutWmsGoodsList);
                        newOutWmsGoodsList.clear(); // 清空列表以准备下一次提交
                    }
                }

                // 如果最后一批不足100条，也需要提交
                if (!newOutWmsGoodsList.isEmpty()) {
                    submitOutWmsGoodsList(newOutWmsGoodsList);
                    newOutWmsGoodsList.clear();
                }

                isSuccess = true;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            exceptionInfo = e.getMessage();
        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }

    // 提交订单拣选列表的方法
    private void submitOutWmsGoodsList(List<OutWmsGoods> outWmsGoodsList ) {

        String strRet = httpPost_saveWmsGoods(outWmsGoodsList);
        NribResult result = JSON.parseObject(strRet,NribResult.class);
        logger.info("post responseData====> {}", strRet); // log返回值

        // 返回成功
        if(result!= null && result.code.equals("200")){
            for (var os : outWmsGoodsList) {
                os.setTrans_status("1");
                wmsInOutMapper.updateOutWmsGoods(os); // 成功 trans_status = 1
            }
        }
    }

    @Override
    public boolean outDistributionOrderTask() {

        boolean isSuccess = false;
        String jobName ="保存拣货数量回传";
        String jobTag ="outDistributionOrderTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 执行存储过程
//            HashMap<String, Object> params = new HashMap<>();
//            wmsInOutMapper.callSpSqlOutPickerRecord(params);
//            String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
//            logger.info("[outDistributionOrderTask] 返回消息 sp_out = {}", spOut);


            // 查询数据
            List<OutDistributionOrder> outDistributionOrderList = wmsInOutMapper.selectOutDistributionOrderList();

            // 提交接口
            List<OutDistributionOrder> newOutDistributionOrderList = new ArrayList<>();
            if (outDistributionOrderList != null && outDistributionOrderList.size() > 0) {

                // 按linecode线路分组
                Map<String, List<OutDistributionOrder>> groupedByLinecode
                        = outDistributionOrderList.stream().collect(Collectors.groupingBy(
                                OutDistributionOrder::getLinecode   // 按线路分组
                        ));

                /// 遍历分组后的记录
                for (Map.Entry<String, List<OutDistributionOrder>> entry : groupedByLinecode.entrySet()) {
                    String linecode = entry.getKey();
                    logger.info("linecode = " + linecode );

                    List<OutDistributionOrder> recordsForLinecode = entry.getValue();

                    // 将当前pickbillno的记录添加到newOutPickerRecordList
                    newOutDistributionOrderList.addAll(recordsForLinecode);

                    // 提交所有当前批次的记录
                    submitOutDistributionOrderList(new ArrayList<>(newOutDistributionOrderList));
                    // 清空newOutPickerRecordList以准备下一次添加
                    newOutDistributionOrderList.clear();
                }

                // 提交剩余的记录，如果有的话
                if (!newOutDistributionOrderList.isEmpty()) {
                    submitOutDistributionOrderList(newOutDistributionOrderList);
                    newOutDistributionOrderList.clear();
                }

                // 清空分组Map以准备下一次操作
                groupedByLinecode.clear();


                /// //////////////////

                /*int count = 0; // 用于跟踪已处理的记录数
                String str_invOrg = "";
                String str_consignor = "";

                for (var outDistributionOrder : outDistributionOrderList) {
                    // 添加当前记录到临时列表
                    newOutDistributionOrderList.add(outDistributionOrder);
                    count++;

                    // 检查是否达到100条记录，如果是，则提交并清空列表
                    if (count % 50 == 0) {

                        submitOutDistributionOrderList(newOutDistributionOrderList);
                        newOutDistributionOrderList.clear(); // 清空列表以准备下一次提交
                    }
                }

                // 如果最后一批不足100条，也需要提交
                if (!newOutDistributionOrderList.isEmpty()) {
                    submitOutDistributionOrderList(newOutDistributionOrderList);
                    newOutDistributionOrderList.clear();
                }*/

                isSuccess = true;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            exceptionInfo = e.getMessage();
        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }

    // 提交订单拣选列表的方法
    private void submitOutDistributionOrderList(List<OutDistributionOrder> outDistributionOrderList ) {

        String strRet = httpPost_saveDistributionOrder(outDistributionOrderList);
        NribResult result = JSON.parseObject(strRet,NribResult.class);
        logger.info("post responseData====> {}", strRet); // log返回值

        // 返回成功
        if(result!= null && result.code.equals("200")){
            for (var os : outDistributionOrderList) {
                os.setTrans_status("1");
                wmsInOutMapper.updateOutDistributionOrder(os); // 成功 trans_status = 1
            }
        }
    }


    @Override
    @Transactional
    public boolean getBilPickInfoTask() {

        boolean isSuccess = false;
        String jobName ="拣货单状态获取";
        String jobTag ="getBilPickInfoTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 查询数据
            List<GetBilPickInfoRequest> pickInfoList = wmsInOutMapper.selectBilPickInfoList();

            String strRet2 = httpPost_getBilPickInfo("001", "SHCW");

            // 提交接口
            if (pickInfoList != null && pickInfoList.size() > 0) {
                for (var pickInfo : pickInfoList) {
                    String invOrg = pickInfo.getInvOrg();
                    String consignor = pickInfo.getConsignor();

                    String strRet = httpPost_getBilPickInfo(pickInfo.getOutdeptcode(), pickInfo.getOutdeptcode());
                    NribResult result = JSON.parseObject(strRet, NribResult.class);
                    logger.info(result.toString());


                    // 返回成功
                    if (result != null && result.code.equals("200")) {

                        List<GetBilPickInfoResponseBody> body = JSON.parseArray(result.body, GetBilPickInfoResponseBody.class);
                        //logger.info(body.toString());

                        // 先情况表再插入数据
                        for (GetBilPickInfoResponseBody item : body) {
                            if (item.getPickstatus() == 2) {
                                for (String bill : item.getEndBillList()) {
//                                wmsInOutMapper.updateSoShipWaveStatus(bill); // 更新标志
                                    // 插入中间表
                                    InPickInfo inPickInfo = new InPickInfo();
                                    inPickInfo.setOutdeptcode(item.getOutdeptcode());
                                    inPickInfo.setBillnum(item.getBillnum());
                                    inPickInfo.setEndbillnum(item.getEndbillnum());
                                    inPickInfo.setPickstatus(item.getPickstatus());
                                    inPickInfo.setEndbill(bill);
                                    wmsInOutMapper.insertInPickInfo(inPickInfo);
                                    // 执行存储过程
//                                HashMap<String, Object> params = new HashMap<>();
//                                params.put("sp_org",invOrg);
//                                params.put("sp_csgor",consignor);
//                                params.put("sp_so", bill );
//                                params.put("sp_user","sync");

//                                String stringList  = wmsInOutMapper.call_SP_SQL_PICK_LIST(params);
                                }
                            }
                        }

                    }

                }

                isSuccess = true;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
            exceptionInfo = e.getMessage();
        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }


    @Override
//    @Transactional
    public boolean inPickPrintLableInfoTask() {

        boolean isSuccess = false;
        String jobName ="标签打印数据获取";
        String jobTag ="inPickPrintLableInfoTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {


            // 查询数据(取push_flag=1)
            List<GetPickPrintLableInfoRequest> pickPrintLableInfoList = wmsInOutMapper.selectPickPrintLableInfoList();

            // 提交接口
            if (pickPrintLableInfoList != null && pickPrintLableInfoList.size() > 0) {
                logger.info("pickPrintLableInfoList.size = " + pickPrintLableInfoList.size());

                // 按线路、门店分组
                String linecode = "";
                Map<String, List<GetPickPrintLableInfoRequest>> groupedByLinecodeStoreCd = pickPrintLableInfoList.stream()
                        .collect(Collectors.groupingBy(
//                            pickPrintLableInfo -> pickPrintLableInfo.getLinecode() + "_" + pickPrintLableInfo.getStoreCd() // 按线路——门店分组
                                pickPrintLableInfo -> pickPrintLableInfo.getLinecode()   // 按线路分组
                        ));

                // 按分组分批次提交
                for (Map.Entry<String, List<GetPickPrintLableInfoRequest>> entry : groupedByLinecodeStoreCd.entrySet()) {
                    List<String> orderIdList = entry.getValue().stream()
                            .map(pickPrintLableInfo -> pickPrintLableInfo.getOrderId().toString().trim())
                            .collect(Collectors.toList());

                    // 提取 linecode
                    linecode = entry.getKey().split("_")[0]; // 从键中提取 linecode
                    //调用太频繁会限流，设置间隔时间，降低频率
                    logger.info("linecode = " + linecode + ",orderIdList.size = " + orderIdList.size());

                    String strRet = httpPost_getPickPrintLableInfo(orderIdList);
                    NribResult result = JSON.parseObject(strRet, NribResult.class);
                    logger.info("post responseData====> {}", strRet);
                    logger.info(result.toString());


                    // 返回成功
                    if (result != null && result.code.equals("200")) {

                        List<InPickPrintLableInfo> body = JSON.parseArray(result.body, InPickPrintLableInfo.class);


                        // 先情况表再插入数据,再执行存储过程 ()
                        batchService.batchInPickPrintLableInfo(body, linecode);
                    }
                }

                isSuccess = true;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            exceptionInfo = e.getMessage();
        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return isSuccess;
    }

    @Override
//    @Transactional
    public boolean inOrderPickStsTask() {

        boolean isSuccess = false;
        String jobName ="拣货单状态获取";
        String jobTag ="inOrderPickStsTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 查询数据(取push_flag=2)
            List<GetOrderPickStsRequest> orderPickStsList = wmsInOutMapper.selectOrderPickStsList();

            // 提交接口
            if (orderPickStsList != null && orderPickStsList.size() > 0) {
                for (var orderPickSts : orderPickStsList) {

                    String strRet = httpPost_getOrderPickSts(orderPickSts.getOrderId(), orderPickSts.getShopCode());
                    NribResult result = JSON.parseObject(strRet, NribResult.class);
                    logger.info(result.toString());

                    // 返回成功
                    if (result != null && result.code.equals("200")) {

                        List<InOrderPickSts> body = JSON.parseArray(result.body, InOrderPickSts.class);
                        //logger.info(body.toString());

                        batchService.batchInOrderPickSts(body, orderPickSts.getInvOrg().trim(), orderPickSts.getConsignor().trim());

                    }

                }

                // 执行存储过程
                if (orderPickStsList.size() > 0) {
                    HashMap<String, Object> params = new HashMap<>();
                    wmsInOutMapper.call_SP_SQL_IN_ORDER_PCIK_STS(params);
                    String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
                    logger.info("[call_SP_SQL_IN_ORDER_PCIK_STS] 返回消息 sp_out = {}", spOut);

                    isSuccess = true;
                    logger.info("[inOrderPickStsTask][拣货单状态获取]------>>数量：" + orderPickStsList.size());

                }


                isSuccess = true;

            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            exceptionInfo = e.getMessage();
        }
        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }

    @Override
//    @Transactional
    public boolean inOrderPickStsListTask() {

        boolean isSuccess = false;
        String jobName ="拣货单状态List获取";
        String jobTag ="inOrderPickStsListTask";
        String jobMsg ="";
        String exceptionInfo ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 查询数据(取push_flag=2)
            List<GetOrderPickStsRequest> orderPickStsList = wmsInOutMapper.selectOrderPickStsList();

            // 提交接口
            List<GetOrderPickStsRequest> newOrderPickStsList = new ArrayList<>();
            if (orderPickStsList != null && orderPickStsList.size() > 0) {
                int count = 0; // 用于跟踪已处理的记录数
                String str_invOrg = "";
                String str_consignor = "";

                for (var orderPickSts : orderPickStsList) {
                    // 添加当前记录到临时列表
                    newOrderPickStsList.add(orderPickSts);
                    str_invOrg = orderPickSts.getInvOrg().trim();
                    str_consignor = orderPickSts.getConsignor().trim();
                    count++;

                    // 检查是否达到100条记录，如果是，则提交并清空列表
                    if (count % 50 == 0) {

                        submitOrderPickStsList(newOrderPickStsList, str_invOrg, str_consignor);
                        newOrderPickStsList.clear(); // 清空列表以准备下一次提交
                    }
                }

                // 如果最后一批不足100条，也需要提交
                if (!newOrderPickStsList.isEmpty()) {
                    submitOrderPickStsList(newOrderPickStsList, str_invOrg, str_consignor);
                    newOrderPickStsList.clear();
                }

                // 执行存储过程
                if (orderPickStsList.size() > 0) {
                    HashMap<String, Object> params = new HashMap<>();
                    wmsInOutMapper.call_SP_SQL_IN_ORDER_PCIK_STS(params);
                    String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
                    logger.info("[call_SP_SQL_IN_ORDER_PCIK_STS] 返回消息 sp_out = {}", spOut);

                    logger.info("[inOrderPickStsListTask][拣货单状态获取]------>>数量：" + orderPickStsList.size());

                }
                isSuccess = true;
            }
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            exceptionInfo = e.getMessage();
        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }



    // 提交订单拣选列表的方法
    private void submitOrderPickStsList(List<GetOrderPickStsRequest> orderPickStsList,String invOrg,String consignor ) {

        String strRet = httpPost_getOrderPickStsList(orderPickStsList);
        NribResult result = JSON.parseObject(strRet,NribResult.class);
        // logger.info(strRet);

        // 返回成功
        if(result!= null && result.code.equals("200")){

            List<InOrderPickSts> body = JSON.parseArray(result.body,InOrderPickSts.class);

            batchService.batchInOrderPickSts(body,invOrg,consignor);

        }
    }

    @Override
    @Transactional
    public boolean getDeptPickStatus() {

        boolean isSuccess = false;
        String jobName ="库区拣货监控";
        String jobTag ="getDeptPickStatus";
        String jobMsg ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            int diffminute = wmsInOutMapper.selectMaxInGetDeptPickStatus();

            if (diffminute > 0) {
                logger.info("超过" + diffminute + "分钟，调用接口");

                // 调用接口获取数据
                String strRet = httpPost_getDeptPickStatus();
                NribResult result = JSON.parseObject(strRet, NribResult.class);
                logger.info(result.toString());

                // 返回成功
                if (result != null && result.code.equals("200")) {

                    List<InGetDeptPickStatus> itemList = JSON.parseArray(result.body, InGetDeptPickStatus.class);

                    // 先情况表再插入数据
                    wmsInOutMapper.deleteInGetDeptPickStatus();
                    for (InGetDeptPickStatus item : itemList) {

                        int cnt = wmsInOutMapper.insertInGetDeptPickStatus(item);
                    }

                }

            } else {
                logger.info("不超过1分钟,直接返回");
            }

            isSuccess = true;
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
        }


        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        //jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",""); // 记录日志

        //logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        //logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return isSuccess;
    }

    @Override
    @Transactional
    public boolean getStorePickStatus() {

        boolean isSuccess = false;
        String jobName ="门店拣货监控";
        String jobTag ="getStorePickStatus";
        String jobMsg ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            int diffminute = wmsInOutMapper.selectMaxInGetStorePickStatus();

            if (diffminute > 0) {
                logger.info("超过" + diffminute + "分钟，调用接口");

                // 调用接口获取数据
                String strRet = httpPost_getStorePickStatus();
                NribResult result = JSON.parseObject(strRet, NribResult.class);
                logger.info(result.toString());

                // 返回成功
                if (result != null && result.code.equals("200")) {

                    List<InGetStorePickStatus> itemList = JSON.parseArray(result.body, InGetStorePickStatus.class);

                    // 先情况表再插入数据
                    wmsInOutMapper.deleteInGetStorePickStatus();
                    for (InGetStorePickStatus item : itemList) {

                        int cnt = wmsInOutMapper.insertInGetStorePickStatus(item);
                    }

                }

            } else {
                logger.info("不超过1分钟,直接返回");
            }

            isSuccess = true;
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
        }


        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        //jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",""); // 记录日志

        //logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        //logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return isSuccess;
    }

    @Override
    @Transactional
    public boolean getLinePickStatus() {

        boolean isSuccess = false;
        String jobName ="路线拣货监控";
        String jobTag ="getLinePickStatus";
        String jobMsg ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            int diffminute = wmsInOutMapper.selectMaxInGetLinePickStatus();

            if (diffminute > 0) {
                logger.info("超过" + diffminute + "分钟，调用接口");

                // 调用接口获取数据
                String strRet = httpPost_getLinePickStatus();
                NribResult result = JSON.parseObject(strRet, NribResult.class);
                logger.info(result.toString());

                // 返回成功
                if (result != null && result.code.equals("200")) {

                    List<InGetLinePickStatus> itemList = JSON.parseArray(result.body, InGetLinePickStatus.class);

                    // 先情况表再插入数据
                    wmsInOutMapper.deleteInGetLinePickStatus();
                    for (InGetLinePickStatus item : itemList) {

                        int cnt = wmsInOutMapper.insertInGetLinePickStatus(item);
                    }

                }

            } else {
                logger.info("不超过1分钟,直接返回");
            }

            isSuccess = true;
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
        }


        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        //jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",""); // 记录日志

        //logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        //logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return isSuccess;
    }

    @Override
    public String checkOverdue(String orderId,String articleId) {

        boolean isSuccess = false;
        String jobName ="检查超期二分之一通知信息";
        String jobTag ="checkOverdue";
        String jobMsg ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();


        // 调用接口获取数据
        String strRet = httpPost_checkOverdue(orderId,articleId);
        NribResult result = JSON.parseObject(strRet,NribResult.class);
        logger.info(result.toString());

        // 返回成功
        if(result!= null && result.code.equals("200")){

        }


        isSuccess =true;


        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        //jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",""); // 记录日志

        //logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        //logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return strRet;
    }

    @Override
    public String getStoreReturnList(String vendorId) {

        boolean isSuccess = false;
        String jobName ="读取退货商品数据";
        String jobTag ="getWmsStoreReturnList";
        String jobMsg ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();
        String strRet = "";

        try {
            // 调用接口获取数据
            strRet = httpPost_getStoreReturnList(vendorId);
            NribResult result = JSON.parseObject(strRet, NribResult.class);
            logger.info(result.toString());

            // 返回成功
            if (result != null && result.code.equals("200")) {

            }


            isSuccess = true;
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
        }


        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        //jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",""); // 记录日志

        //logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        //logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");
        return strRet;
    }


    @Override
    @Transactional
    public boolean syncHYStockATask() {

        boolean isSuccess = false;
        String jobName ="同步HY库存";
        String jobTag ="syncHYStockATask";
        String jobMsg ="";
        String exceptionInfo = "";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "同步数据开始"));
        long startTime = System.currentTimeMillis();

        try {
            // 执行存储过程
            // 备份数据
            HashMap<String, Object> params0 = new HashMap<>();
            wmsInOutMapper.call_SP_SQL_BACKUP_DATA(params0);
            String spOut0 = (String) params0.get("spOut"); // 从params中获取存储过程输出的结果
            logger.info("[syncHYStockATask][同步HY库存]------>> call_SP_SQL_BACKUP_DATA 返回消息 sp_out = {}", spOut0);

            // 同步HY库存
            HashMap<String, Object> params = new HashMap<>();
            wmsInOutMapper.call_SP_SQL_SYNC_HYSTOCK_A(params);
            String spOut = (String) params.get("spOut"); // 从params中获取存储过程输出的结果
            logger.info("[syncHYStockATask][同步HY库存]------>> call_SP_SQL_SYNC_HYSTOCK_A 返回消息 sp_out = {}", spOut);

        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error(e.getMessage());
            TransactionAspectSupport.currentTransactionStatus().setRollbackOnly();// 手动回滚
            exceptionInfo = e.getMessage();

        }

        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg += "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",exceptionInfo); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }

    @Override
//    @Transactional
    public boolean testTask() {

        boolean isSuccess = false;

        String jobName ="测试任务Job";
        String jobTag ="testTask";
        String jobMsg ="";
        logger.info(String.format("[%s][%s]------>>%s", jobTag, jobName, "更新数据开始"));

        long startTime = System.currentTimeMillis();


        long endTime = System.currentTimeMillis();
        long duration = endTime - startTime;
        jobMsg = "耗时：" + duration + "毫秒";

        jobLog(jobName,"DEFAULT",jobTag,jobMsg,"0",""); // 记录日志

        logger.info("[{}][{}]------>>{}",jobTag, jobName, jobMsg);
        logger.info("[{}][{}]------>>{}",jobTag, jobName, "同步数据完成");

        return isSuccess;
    }


    // 记录日志
    @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRES_NEW)
    public int jobLog(String jobName, String jobGroup, String jobTag, String jobMsg, String status, String exceptionInfo){
//        try{
//            return sysJobLogMapper.insert(new SysJobLog(jobName,jobGroup,jobTag,jobName + " " +jobMsg,status,exceptionInfo));
//        }
//        catch (Exception e){
//            e.printStackTrace();
//            logger.error(e.getMessage());
//            return 0;
//        }

        return batchService.jobLog(jobName, jobGroup, jobTag, jobMsg, status, exceptionInfo);

    }



    // 调用野村接口-1、商品主档
    public String httpPost_getArticleList() {
        return httpPost_callApiCenter("","1","0","getArticleList");
    }

    // 调用野村接口-2、店铺档案
    public String httpPost_getStoreList() {
        return httpPost_callApiCenter("","1","0","getStoreList");
    }

    // 调用野村接口-3、供应商档案
    public String httpPost_getVendorList() {
        return httpPost_callApiCenter("","1","0","getVendorList");
    }

    // 调用野村接口-4、路线
    public String httpPost_getRouteList() {
        return httpPost_callApiCenter("","1","0","getRouteList");
    }

    // 调用野村接口-16、wms获取商品附加属性
    public String httpPost_getInfGoodsMore() {
        return httpPost_callApiCenter("","1","0","getInfGoodsMore");
    }

    // 调用野村接口-17、wms获取货位信息
    public String httpPost_getInfStockPosition() {
        return httpPost_callApiCenter("","1","0","getInfStockPosition");
    }

    // 调用野村接口-17、wms获取货位信息
    public String httpPost_getWmsStockByPosition() {
        return httpPost_callApiCenter("","1","0","getWmsStockByPosition");
    }

    // 调用野村接口-4.37 获取大库成本
    public String httpPost_getDCCost() {

        Map<String, String> params = new HashMap<>(); // body = {}
        return httpPost_callApiCenter_common(params,"getDCCost");
    }

    // 调用野村接口-4.38 获取供应商
    public String httpPost_getMasterVendor() {

        List<String> params = new ArrayList<>(); // body = []
        return httpPost_callApiCenter_common(params,"getMasterVendor");
    }

    // 调用野村接口-20、门店退仓库退货申请
    public String httpPost_getStoreToDcApply(String startDate,String endDate) {

        Map<String, String> params = new HashMap<>();
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        return httpPost_callApiCenter_common(params,"getStoreToDcApply");
    }

    // 调用野村接口-4.21 仓库退供应商退货申请
    public String httpPost_getDcToSupplierApply(String startDate,String endDate) {

        Map<String, String> params = new HashMap<>();
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        return httpPost_callApiCenter_common(params,"getDcToSupplierApply");
    }



    // 调用野村接口-5、收货指令接收
    public String httpPost_getTransInDtl(String asnType,String startDate,String endDate) {
        return httpPost_callApiCenter_asn(asnType,startDate,endDate,"1","0","getTransInDtl");
    }

    // 调用野村接口-6、发货指令接收
    public String httpPost_getTransOutDtl(String soType,String startDate,String endDate,String soNo) {
        return httpPost_callApiCenter_so(soNo,soType,startDate,endDate,"1","0","getTransOutDtl");
    }

    // 调用野村接口-7、收货单回传
    public String httpPost_saveReceiveDtl(List<OutAsn> outAsn) {
        return httpPost_callApiCenter_out(outAsn,"saveReceiveDtl");
    }

    // 调用野村接口-8、发货单回传
    public String httpPost_saveDeliveryDtl(List<OutSo> outSo) {
        return httpPost_callApiCenter_out(outSo,"saveDeliveryDtl");
    }

    // 调用野村接口-8、退货单回传
    public String httpPost_saveGoodsReturnSupplier(List<OutSo2> outSo2) {
        return httpPost_callApiCenter_out(outSo2,"saveGoodsReturnSupplier");
    }

    // 调用野村接口-4.22 门店退仓库实际退货回传
    public String httpPost_saveStoreToDcStock(List<OutAsn2> outAsn2s) {
        return httpPost_callApiCenter_out(outAsn2s,"saveStoreToDcStock");
    }

    // 调用野村接口-9、每日库存回传
    public String httpPost_saveInventoryDaily(List<OutInv> outInv) {
        return httpPost_callApiCenter_out(outInv,"saveInventoryDaily");
    }

    // 调用野村接口-10、库存异动回传
    public String httpPost_saveInventoryMovement(List<OutInv2>  outInv2) {
        return httpPost_callApiCenter_out(outInv2,"saveInventoryMovement");
    }

    // 调用野村接口- 报损调整回传
    public String httpPost_saveWriteOffRecord(List<OutInv2BS>  outInv2BS) {
        return httpPost_callApiCenter_out(outInv2BS,"saveWriteOffRecord");
    }

    // 调用野村接口-4.26 保存拣货人记录
    public String httpPost_savePickerRecord(List<OutPickerRecord>  outPickerRecordList) {
        return httpPost_callApiCenter_out(outPickerRecordList,"savePickerRecord");
    }

    // 调用野村接口-4.35 保存拣货数量
    public String httpPost_saveWmsGoods(List<OutWmsGoods>  outWmsGoodsList) {
        return httpPost_callApiCenter_out(outWmsGoodsList,"saveWmsGoods");
    }

    // 调用野村接口-4.36保存配送单
    public String httpPost_saveDistributionOrder(List<OutDistributionOrder>  outDistributionOrderList) {
        return httpPost_callApiCenter_out(outDistributionOrderList,"saveDistributionOrder");
    }

    // 调用野村接口-12、拣货单状态获取
    public String httpPost_getBilPickInfo(String outdeptcode,String shopcode) {
        return httpPost_callApiCenter_getBilPickInfo(outdeptcode, shopcode, "getBillPickInfo");
    }

    // 调用野村接口-14、拣货单状态获取 （新）
    public String httpPost_getOrderPickSts(String orderId ,String shopCode ) {
        return httpPost_callApiCenter_getOrderPickSts(orderId , shopCode , "getOrderPickSts");
    }

    // 调用野村接口-14、拣货单状态获取 （新）
    public String httpPost_getOrderPickStsList(List<GetOrderPickStsRequest> orderPickStsList ) {
        return httpPost_callApiCenter_getOrderPickStsList(orderPickStsList, "getOrderPickStsList");
    }

    // 调用野村接口-24、获取pick详情
    public String httpPost_getPickPrintLableInfo(List<String>  orderIdList  ) {
        return httpPost_callApiCenter_out(orderIdList  , "getPickPrintLableInfo");
    }

    // 调用野村接口-15、获取商品库存
    public String httpPost_getWmsStock() {
        return httpPost_callApiCenter_getWmsStock("1","0",null,"getWmsStock");
    }

    // 调用野村接口-27
    public String httpPost_getDeptPickStatus() {
        return httpPost_callApiCenter_out(new Object(),"getDeptPickStatus");
    }
    public String httpPost_getStorePickStatus() {
        return httpPost_callApiCenter_out(new Object(),"getStorePickStatus");
    }
    public String httpPost_getLinePickStatus() {
        return httpPost_callApiCenter_out(new Object(),"getLinePickStatus");
    }
    public String httpPost_checkOverdue(String orderId,String articleId) {

        Map<String, String> map = new HashMap<>();
        map.put("orderId", orderId);
        map.put("articleId", articleId);

        return httpPost_callApiCenter_out(map,"checkOverdue");
    }

    public String httpPost_getStoreReturnList(String vendorId) {

        Map<String, String> map = new HashMap<>();
        map.put("vendorId", vendorId);

        return httpPost_callApiCenter_out(map,"getStoreReturnList");
    }



    /**
     * 查询主档数据
     * @param strQuery
     * @param strPageSize
     * @param strPage
     * @param strApiService
     * @return
     */
    public String httpPost_callApiCenter(String strQuery,String strPageSize,String strPage,String strApiService) {


        String result = "";

        try{
            // 商品主档-body请求参数
            GetArticleListRequest request = new GetArticleListRequest();
            // request.setQueryStr(""); // 模糊查询
            request.setPage(strPageSize);       // 页码
            request.setPageSize(strPage);   // 每页大小 (当前页面展示几条, 不分页传入 0)
            String strBody = JSON.toJSONString(request);

            // 参数
            PublicParams params = new PublicParams();
            params.setCompanyCd(jiumiConfig.getCompanyCd() );
            params.setTimestamp(DateUtils.dateTimeNow());
            params.setApiService(strApiService);
            params.setBody(strBody);
            String strSign =  Md5Sign(jiumiConfig.getSecreteKey(),JSON.toJSONString(params))  ; // 签数签名
            params.setSignature(strSign);
            String strJsonParams = JSON.toJSONString(params);

            // 调用接口
            //result = HttpUtils.sendPostRequest(jiumiConfig.getApiUrl(),"", strJsonParams);
            result = OkHttpUtil.post(jiumiConfig.getApiUrl(),JSON.parseObject(strJsonParams));

        }catch (Exception ex){
            logger.info("{} ====>报错：" + ex.getMessage(),strApiService);
        }

        return result;
    }

    /**
     * 收货单指令传递
     * @param asnType  订单类型 01-订单, 02-门店退货
     * @param startDate 开始日期 日期格式: yyyyMMdd
     * @param endDate   结束日期 日期格式: yyyyMMdd
     * @param strPageSize 页码
     * @param strPage 每页大小
     * @param strApiService
     * @return
     */
    public String httpPost_callApiCenter_asn(String asnType,String startDate,String endDate,String strPageSize,String strPage,String strApiService) {


        String result = "";

        try{
            // body请求参数
            GetTransInDtlRequest request = new GetTransInDtlRequest();

            request.setAsnType(asnType);        // 订单类型 01-订单, 02-门店退货
            request.setStartDate(startDate);    // 开始日期
            request.setEndDate(endDate);        // 结束日期
            request.setPage(strPageSize);       // 页码
            request.setPageSize(strPage);       // 每页大小 (当前页面展示几条, 不分页传入 0)
            String strBody = JSON.toJSONString(request);

            // 参数
            PublicParams params = new PublicParams();
            params.setCompanyCd(jiumiConfig.getCompanyCd() );
            params.setTimestamp(DateUtils.dateTimeNow());
            params.setApiService(strApiService);
            params.setBody(strBody);
            String strSign =  Md5Sign(jiumiConfig.getSecreteKey(),JSON.toJSONString(params))  ; // 签数签名
            params.setSignature(strSign);
            String strJsonParams = JSON.toJSONString(params);

            // 调用接口
            //result = HttpUtils.sendPostRequest(jiumiConfig.getApiUrl(),"", strJsonParams);
            result = OkHttpUtil.post(jiumiConfig.getApiUrl(),JSON.parseObject(strJsonParams));

        }catch (Exception ex){
            logger.info("{} ====>报错：" + ex.getMessage(),strApiService);
        }

        return result;
    }

    /**
     * 收货单指令传递
     * @param soType  订单类型 01-门店要货单, 02-调出仓
     * @param startDate 开始日期 日期格式: yyyyMMdd
     * @param endDate   结束日期 日期格式: yyyyMMdd
     * @param strPageSize 页码
     * @param strPage 每页大小
     * @param strApiService
     * @return
     */
    public String httpPost_callApiCenter_so(String soNo,String soType,String startDate,String endDate,String strPageSize,String strPage,String strApiService) {


        String result = "";

        try{
            // body请求参数
            GetTransOutDtlRequest request = new GetTransOutDtlRequest();

            request.setSoNo(soNo);              // 单号
            request.setSoType(soType);          // 01-门店要货单, 02-调出仓库
            request.setStartDate(startDate);    // 开始日期
            request.setEndDate(endDate);        // 结束日期
            request.setPage(strPageSize);       // 页码
            request.setPageSize(strPage);       // 每页大小 (当前页面展示几条, 不分页传入 0)
            String strBody = JSON.toJSONString(request);

            // 参数
            PublicParams params = new PublicParams();
            params.setCompanyCd(jiumiConfig.getCompanyCd() );
            params.setTimestamp(DateUtils.dateTimeNow());
            params.setApiService(strApiService);
            params.setBody(strBody);
            String strSign =  Md5Sign(jiumiConfig.getSecreteKey(),JSON.toJSONString(params))  ; // 签数签名
            params.setSignature(strSign);
            String strJsonParams = JSON.toJSONString(params);

            // 调用接口
            //result = HttpUtils.sendPostRequest(jiumiConfig.getApiUrl(),"", strJsonParams);
            result = OkHttpUtil.post(jiumiConfig.getApiUrl(),JSON.parseObject(strJsonParams));

        }catch (Exception ex){
            logger.info("{} ====>报错：" + ex.getMessage(),strApiService);
        }

        return result;
    }

    /**
     * 回传数据接口（通用）
     * @param obj
     * @param strApiService
     * @param <T>
     * @return
     */
    public <T> String httpPost_callApiCenter_out(T obj, String strApiService) {


        String result = "";

        try{
            // body请求参数
            String strBody = JSON.toJSONString(obj);

            // 参数
            PublicParams params = new PublicParams();
            params.setCompanyCd(jiumiConfig.getCompanyCd() );
            params.setTimestamp(DateUtils.dateTimeNow());
            params.setApiService(strApiService);
            params.setBody(strBody);
            String strSign =  Md5Sign(jiumiConfig.getSecreteKey(),JSON.toJSONString(params))  ; // 签数签名
            params.setSignature(strSign);
            String strJsonParams = JSON.toJSONString(params);

            // 调用接口
            //result = HttpUtils.sendPostRequest(jiumiConfig.getApiUrl(),"", strJsonParams);
            result = OkHttpUtil.post(jiumiConfig.getApiUrl(),JSON.parseObject(strJsonParams));

        }catch (Exception ex){
            logger.info("{} ====>报错：" + ex.getMessage(),strApiService);
        }

        return result;
    }

    /**
     * 拣货单状态获取 (旧)
     * @param outdeptcode   库区
     * @param shopcode      店铺号
     * @param strApiService
     * @return
     */
    public String httpPost_callApiCenter_getBilPickInfo(String outdeptcode,String shopcode,String strApiService) {


        String result = "";

        try{
            // body请求参数
            GetBilPickInfoRequest request = new GetBilPickInfoRequest();

            request.setOutdeptcode(outdeptcode);        // 库区
            request.setShopcode(shopcode);              // 店铺号
            String strBody = JSON.toJSONString(request);

            // 参数
            PublicParams params = new PublicParams();
            params.setCompanyCd(jiumiConfig.getCompanyCd() );
            params.setTimestamp(DateUtils.dateTimeNow());
            params.setApiService(strApiService);
            params.setBody(strBody);
            String strSign =  Md5Sign(jiumiConfig.getSecreteKey(),JSON.toJSONString(params))  ; // 签数签名
            params.setSignature(strSign);
            String strJsonParams = JSON.toJSONString(params);

            // 调用接口
            //result = HttpUtils.sendPostRequest(jiumiConfig.getApiUrl(),"", strJsonParams);
            result = OkHttpUtil.post(jiumiConfig.getApiUrl(),JSON.parseObject(strJsonParams));

        }catch (Exception ex){
            logger.info("{} ====>报错：" + ex.getMessage(),strApiService);
        }

        return result;
    }

    /**
     * 拣货单状态获取 (新)
     * @param orderId   库区
     * @param shopCode       店铺号
     * @param strApiService
     * @return
     */
    public String httpPost_callApiCenter_getOrderPickSts(String orderId ,String shopCode ,String strApiService) {


        String result = "";

        try{
            // body请求参数
            GetOrderPickStsRequest request = new GetOrderPickStsRequest();
            request.setOrderId(orderId.toString().trim());        // 库区
            request.setShopCode(shopCode.toString().trim());              // 店铺号
            String strBody = JSON.toJSONString(request);

            // 参数
            PublicParams params = new PublicParams();
            params.setCompanyCd(jiumiConfig.getCompanyCd() );
            params.setTimestamp(DateUtils.dateTimeNow());
            params.setApiService(strApiService);
            params.setBody(strBody);
            String strSign =  Md5Sign(jiumiConfig.getSecreteKey(),JSON.toJSONString(params))  ; // 签数签名
            params.setSignature(strSign);
            String strJsonParams = JSON.toJSONString(params);

            // 调用接口
            result = OkHttpUtil.post(jiumiConfig.getApiUrl(),JSON.parseObject(strJsonParams));

        }catch (Exception ex){
            logger.info("{} ====>报错：" + ex.getMessage(),strApiService);
        }

        return result;
    }

    /**
     *  4.25订单揽货状态获取List
     * @param reqList
     * @param strApiService
     * @return
     */
    public String httpPost_callApiCenter_getOrderPickStsList(List<GetOrderPickStsRequest> reqList ,String strApiService) {


        String result = "";

        try{
            // body请求参数
//            GetOrderPickStsRequest request = new GetOrderPickStsRequest();
//            request.setOrderId(orderId.toString().trim());        // 库区
//            request.setShopCode(shopCode.toString().trim());              // 店铺号
            String strBody = JSON.toJSONString(reqList);

            // 参数
            PublicParams params = new PublicParams();
            params.setCompanyCd(jiumiConfig.getCompanyCd() );
            params.setTimestamp(DateUtils.dateTimeNow());
            params.setApiService(strApiService);
            params.setBody(strBody);
            String strSign =  Md5Sign(jiumiConfig.getSecreteKey(),JSON.toJSONString(params))  ; // 签数签名
            params.setSignature(strSign);
            String strJsonParams = JSON.toJSONString(params);

            // 调用接口
            result = OkHttpUtil.post(jiumiConfig.getApiUrl(),JSON.parseObject(strJsonParams));

        }catch (Exception ex){
            logger.info("{} ====>报错：" + ex.getMessage(),strApiService);
        }

        return result;
    }

    /**
     * 查询主档数据
     * @param strPageSize
     * @param strPage
     * @param articleldList
     * @param strApiService
     * @return
     */
    public String httpPost_callApiCenter_getWmsStock(String strPageSize,String strPage,List<String> articleldList,String strApiService) {


        String result = "";

        try{
            // 商品主档-body请求参数
            GetArticleListRequest request = new GetArticleListRequest();
            // request.setQueryStr(""); // 模糊查询
            request.setPage(strPageSize);       // 页码
            request.setPageSize(strPage);   // 每页大小 (当前页面展示几条, 不分页传入 0)
            String strBody = JSON.toJSONString(request);

            // 参数
            PublicParams params = new PublicParams();
            params.setCompanyCd(jiumiConfig.getCompanyCd() );
            params.setTimestamp(DateUtils.dateTimeNow());
            params.setApiService(strApiService);
            params.setBody(strBody);
            String strSign =  Md5Sign(jiumiConfig.getSecreteKey(),JSON.toJSONString(params))  ; // 签数签名
            params.setSignature(strSign);
            String strJsonParams = JSON.toJSONString(params);

            // 调用接口
            //result = HttpUtils.sendPostRequest(jiumiConfig.getApiUrl(),"", strJsonParams);
            result = OkHttpUtil.post(jiumiConfig.getApiUrl(),JSON.parseObject(strJsonParams));

        }catch (Exception ex){
            logger.info("{} ====>报错：" + ex.getMessage(),strApiService);
        }

        return result;
    }

    /**
     * 查询主档数据
     * @param objParams
     * @param strApiService
     * @return
     */
    public String httpPost_callApiCenter_common(Object objParams,String strApiService) {


        String result = "";

        try{
            // 商品主档-body请求参数
            String strBody = JSON.toJSONString(objParams);

            // 参数
            PublicParams params = new PublicParams();
            params.setCompanyCd(jiumiConfig.getCompanyCd() );
            params.setTimestamp(DateUtils.dateTimeNow());
            params.setApiService(strApiService);
            params.setBody(strBody);
            String strSign =  Md5Sign(jiumiConfig.getSecreteKey(),JSON.toJSONString(params))  ; // 签数签名
            params.setSignature(strSign);
            String strJsonParams = JSON.toJSONString(params);

            // 调用接口
            //result = HttpUtils.sendPostRequest(jiumiConfig.getApiUrl(),"", strJsonParams);
            result = OkHttpUtil.post(jiumiConfig.getApiUrl(),JSON.parseObject(strJsonParams));

        }catch (Exception ex){
            logger.info("{} ====>报错：" + ex.getMessage(),strApiService);
        }

        return result;
    }




    // Method to sort JSON keys and concatenate key-value pairs
    public static String Md5Sign(String secreteKey ,String jsonStr) {
        // Parse JSON string into JSONObject
        JSONObject jsonObject = JSON.parseObject(jsonStr);

        // Create a TreeMap to sort keys in ascending ASCII order
        TreeMap<String, Object> sortedMap = new TreeMap<>();
        for (String key : jsonObject.keySet()) {
            sortedMap.put(key, jsonObject.get(key));
        }

        // Concatenate key-value pairs
        StringBuilder sb = new StringBuilder();
        for (Map.Entry<String, Object> entry : sortedMap.entrySet()) {
            String key = entry.getKey();
            Object value = entry.getValue();
            sb.append(key).append(value.toString());
        }

        String contentName = secreteKey + sb.toString() + secreteKey;
        String md5str = DigestUtils.md5Hex(contentName);; // 加密后md5
        // 加密后的字符串
//        String md5str = DigestUtils.md5Hex(text);
        //32位，小写
        String md532Lower = md5str.toString();
        //32位，大写
//        String md532Upper=md532Lower.toUpperCase();
        //16位，小写
//        String md516Lower =md532Lower.substring(8, 24);
        //16位，大写
        String md516Upper=md532Lower.substring(8, 24).toUpperCase();

        return md516Upper;
    }

}
